/******************************************************************************/
#ifndef	_MY_TYPE_H_
#define	_MY_TYPE_H_

typedef volatile unsigned char vu8;
typedef volatile unsigned int  vu16;
typedef volatile unsigned long vu32;
typedef volatile unsigned long long vu64;

typedef unsigned char u8;
typedef unsigned int  u16;
typedef unsigned long u32;
typedef unsigned long long u64;

typedef signed char s8;
typedef signed int  s16;
typedef signed long s32;
typedef signed long long s64;

typedef unsigned char uint8;
typedef unsigned int  uint16;
typedef unsigned long uint32;
typedef unsigned long long uint64;

typedef signed char int8;
typedef signed int  int16;
typedef signed long int32;
typedef signed long long int64;


#define ENABLE (1)
#define DISABLE (0)

#define ON (1)
#define OFF (0)


typedef struct
{
    unsigned char bit0 : 1;
    unsigned char bit1 : 1;
    unsigned char bit2 : 1;
    unsigned char bit3 : 1;
    unsigned char bit4 : 1;
    unsigned char bit5 : 1;
    unsigned char bit6 : 1;
    unsigned char bit7 : 1;
} bit_type;


typedef union
{
	struct
	{      
	  u8	error  	:4;
	  u8	NoPan  	:1;
 	  u8	nc		:3;
	}flagBit;    
	u8 m_data;    
}IH_Status_FLAG; 


typedef union
{
	struct
	{      		
	  vu8	p_t_set	:1;	
	  vu8	beep	:2;		
	  vu8	on_off	:2;
	  vu8	fan		:2;
	  vu8	undfine	:1;
	}flagBit;    
	vu8 m_data;    
}ControlSet_Flag;




static volatile bit_type bit_var00 __attribute__ ((at(0x080)));
static volatile bit_type bit_var01 __attribute__ ((at(0x081)));
static volatile bit_type bit_var02 __attribute__ ((at(0x082)));
static volatile bit_type bit_var03 __attribute__ ((at(0x083)));
static volatile bit_type bit_var04 __attribute__ ((at(0x084)));
static volatile bit_type bit_var05 __attribute__ ((at(0x085)));
static volatile bit_type bit_var06 __attribute__ ((at(0x086)));


#define bT1mS_Event  				bit_var00.bit0	//1ms event flag
#define bT20mS_Event  				bit_var00.bit1	//20ms event flag
#define bT100mS_Event  				bit_var00.bit2	//100ms event flag
#define bT10mS_Event  				bit_var00.bit3	//10ms event flag
#define bT1S_Event  				bit_var00.bit4	//1s event flag
#define bStartPPG					bit_var00.bit5  //PPG Software switch
#define bPowerState					bit_var00.bit6  //PPG open flagㄩ1
#define bOVP_Adj       				bit_var00.bit7 	//Comparator synchronization to adjust power
//
#define bMachineOnState 			bit_var01.bit0  //Switch on/off flag
#define bAD_StartCapture 			bit_var01.bit1  //
#define bPowerStepChanged 			bit_var01.bit2  //Power step change flag
#define bPowerAdjStart 				bit_var01.bit3  //Power change adjustment flag
#define bModeChanged				bit_var01.bit4	//Low power to high power flag

//
#define bSurgeHW 					bit_var02.bit0  //Surge detected flag
#define bOverCurrentHW 				bit_var02.bit1  //Overcurrent flag
#define bOverVoltageHW				bit_var02.bit2	//IGBT back pressure flag
#define bIgbtNtcError				bit_var02.bit3  //IGBT NTC error flag
#define bPanNtcError	     		bit_var02.bit4  //Pan NTC error flag
#define bCurrentSurgeHW				bit_var02.bit5  //current Surge flag
#define bErrUnderVoltage 			bit_var02.bit6  //Low voltage flag
#define bErrOverCurrent 			bit_var02.bit7  //ADC sampling current overcurrent
//
#define bErrOverVoltage 			bit_var03.bit0  //Overvoltage flag
#define bErrPowerOff				bit_var03.bit1  //The flag bit that requires shutdown
#define bErrPAD_Otemper	       		bit_var03.bit2 	//Cookware over-temperature flag
#define bErrIGBT_Otemper 	        bit_var03.bit3 	//IGBT over temperature flag
//
#define bAD_Convert_Ok				bit_var04.bit0	//Single acquisition ADC completed flag
#define bAD_DataReady				bit_var04.bit1	//ADC filtering flag
#define bIGBT_HTemp_PowDrop			bit_var04.bit2	//igbt over temp power drop flag
#define bLowPower					bit_var04.bit3	//low power mode flag
#define bLowPowerADJ				bit_var04.bit4  //low power mode adj power falg
#define bLowPowerADJ_PPGA_update	bit_var04.bit5	//reload PPGTA_copy to change power	 flag
#define bBeep_State					bit_var04.bit6	//beep state flag
#define bBeep_ON					bit_var04.bit7	//beep on flag
////-----------------------------------------
//

//**************************************
//			Constant Define 
//**************************************

#define C_PAN_DET_TIMER_100MS 		10 		//10x100mS = 1.0 sec    
#define C_NoPanDetectedOff			30		//20x30x100mS = 60 sec
//
////---------------------------------------------------------------------
#define C_ErrRecoveryTime			3		//Second
////---------------------------------------------------------------------

#define C_V_TOLERANCE  				0 //There is a big difference between the power and no-load voltage AD value when loaded
#define C_AD_70V					(36-C_V_TOLERANCE)
#define C_AD_75V					(38-C_V_TOLERANCE)
#define C_AD_80V					(41-C_V_TOLERANCE)
#define C_AD_90V					(46-C_V_TOLERANCE)
#define C_AD_100V					(51-C_V_TOLERANCE)
#define C_AD_110V					(56-C_V_TOLERANCE)
#define C_AD_120V					(62-C_V_TOLERANCE)
#define C_AD_130V					(67-C_V_TOLERANCE)
#define C_AD_140V					(72-C_V_TOLERANCE)
#define C_AD_145V   				(74-C_V_TOLERANCE)
#define C_AD_150V					(77-C_V_TOLERANCE)
#define C_AD_160V					(83-C_V_TOLERANCE)
#define C_AD_170V					(88-C_V_TOLERANCE)
#define C_AD_175V					(90-C_V_TOLERANCE)
#define C_AD_180V					(93-C_V_TOLERANCE)
#define C_AD_185V					(95-C_V_TOLERANCE)
#define C_AD_190V					(98-C_V_TOLERANCE)
#define C_AD_195V					(100-C_V_TOLERANCE)
#define C_AD_200V					(106-C_V_TOLERANCE)
#define C_AD_205V					(108-C_V_TOLERANCE)
#define C_AD_210V					(112-C_V_TOLERANCE)
#define C_AD_215V					(114-C_V_TOLERANCE)
#define C_AD_220V					(117-C_V_TOLERANCE)
#define C_AD_225V					(119-C_V_TOLERANCE)
#define C_AD_230V					(121-C_V_TOLERANCE)
#define C_AD_235V					(125-C_V_TOLERANCE)
#define C_AD_240V					(128-C_V_TOLERANCE)
#define C_AD_245V					(130-C_V_TOLERANCE)
#define C_AD_250V					(132-C_V_TOLERANCE)
#define C_AD_260V					(138-C_V_TOLERANCE)
#define C_AD_265V					(140-C_V_TOLERANCE)
#define C_AD_270V					(143-C_V_TOLERANCE)
#define C_AD_275V					(145-C_V_TOLERANCE)
#define C_AD_285V					(150-C_V_TOLERANCE)


////---------------------------------------------------------------------

//8BIT_AD NTC temp AD(NTC 100K b3950)
#define C_T_NTC240				11
#define C_T_NTC235				12
#define C_T_NTC230				13

#define C_T_NTC225				24
#define C_T_NTC220				25
#define C_T_NTC215				27
#define C_T_NTC210				29
#define C_T_NTC205				31
#define C_T_NTC200				35	
#define C_T_NTC195				41
#define C_T_NTC190				42
#define C_T_NTC185				45	
#define C_T_NTC180				49
#define C_T_NTC175				52
#define C_T_NTC170				56
#define C_T_NTC165				60
#define	C_T_NTC160				65
#define C_T_NTC155				69
#define	C_T_NTC150				74
#define C_T_NTC145				79
#define	C_T_NTC140				85
#define C_T_NTC135				93
#define	C_T_NTC130				99
#define C_T_NTC125				106
#define	C_T_NTC120				113
#define C_T_NTC115				122
#define C_T_NTC110				130
#define C_T_NTC105				138
#define C_T_NTC100  			147
#define C_T_NTC95				155
#define C_T_NTC90				164
#define C_T_NTC85				173
#define	C_T_NTC80				181
#define C_T_NTC75				189
#define C_T_NTC70 				197
#define C_T_NTC60				214
#define C_T_NTC50				224
#define C_T_NTC40				234	
#define	C_T_NTC30				245
//

////---------------------------------------------------------------------
////NTC abnormal AD value upper and lower limits
#define C_NTC_OPENCIRCUIT  			253		//NTC OPENCIRCUIT value
#define C_NTC_SHORTCIRCUIT 			3		//NTC SHORTCIRCUIT value
//
#define C_T_PAD_NTC_OPENCIRCUIT 	253	//8bit ADC
#define C_T_PAD_NTC_SHORTCIRCUIT 	3	//8bit ADC
//
#define C_T_IGBT_NTC_OPENCIRCUIT 	253
#define C_T_IGBT_NTC_SHORTCIRCUIT 	3
//IGBT TEMP
#define IGBT_NTC_OVERTEMP_LIMIT_POW     C_T_NTC90           // default:90⊥
#define IGBT_NTC_OVERTEMP_POWOFF        C_T_NTC105          // (90~120ㄛdefault:105⊥)
#define C_T_IGBT_RECOVER  				C_T_NTC70			// error recover temp
//PAN TEMP
#define PAN_NTC_OVERTEMP_POWOFF         C_T_NTC170          // default:170⊥
#define	C_T_PAD_RECOVER					C_T_NTC110	    	// error recover temp
//
#define C_NTC_TIMEOUT 				5		//NTC error count
#define C_OvertemperCnt 			5
//					  	
//// Protection constants
#define C_OverVoltageCnt_TH 		10
#define C_UnderVoltageCnt_TH 		10
#define C_OverCurrentCnt_TH 		3
//	
////-------------------------------
//
#define	C_2Min      				120     //2min
#define C_30SEC						30		 //30s
//
//////==== Countinuous Power ======
#define C_PowStep_OFF				0	

//
////---------Common protection, parameter adjustment---------------------------

#define C_MaxVol  					C_AD_260V
#define C_MinVol  					C_AD_150V
////
#define C_AD_9A						118//
#define C_AD_10A					134//
#define C_AD_11A					142//
#define C_AD_12A					154//
#define C_AD_MaxCurrent				C_AD_11A	

#endif
/******************************************************************************/